﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Xiucai.Common;
using Xiucai.Common.Data;
using Xiucai.Common.Data.SqlServer;
using Xiucai.Common.Provider;
using Xiucai.BPM.Core.Model;
namespace Xiucai.BPM.Core.Dal
{
    public class EquipMentRepairDal : BaseRepository<EquipmentRepair>
    {
        public static EquipMentRepairDal Instance
        {
            get { return SingletonProvider<EquipMentRepairDal>.Instance; }
        }

        public int AddEquipMentRepair(EquipmentRepair model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_equipmentRepair(");
            strSql.Append("userId,equKeyId,equType,repairTime,repairContent,repairUserIds,isRead)");
            strSql.Append(" values (");
            strSql.Append("@userId,@equKeyId,@equType,@repairTime,@repairContent,@repairUserIds,@isRead)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@userId", SqlDbType.Int,4),
					new SqlParameter("@equKeyId", SqlDbType.Int,4),
					new SqlParameter("@equType", SqlDbType.VarChar,20),
					new SqlParameter("@repairTime", SqlDbType.DateTime),
					new SqlParameter("@repairContent", SqlDbType.NVarChar,1000),
					new SqlParameter("@repairUserIds", SqlDbType.VarChar,500),
                    new SqlParameter("@isRead", SqlDbType.Bit,1)};
            parameters[0].Value = model.userId;
            parameters[1].Value = model.equKeyId;
            parameters[2].Value = model.equType;
            parameters[3].Value = model.repairTime;
            parameters[4].Value = model.repairContent;
            parameters[5].Value = model.repairUserIds;
            parameters[6].Value = model.isRead;

            object obj = SqlEasy.ExecuteNonQuery(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }

           
        }
    }
}
